
<template>
	<!-- 添加弹框 -->
	<el-dialog title="" visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		 <div class="bt">添加退货</div>
		 <el-form label-width="100px" class="form">
			 <el-form-item label="退货物品">
				 <el-input v-model="vwpid"  placeholder="请选择物品名称" icon="add" class="input" v-if="false" ></el-input>
				 <el-input v-model="vwpidmc" placeholder="请选择物品名称" icon="add" class="input1" :readonly="true"></el-input>
				 <el-button size='small'  @click="componentsShow('xzwp')" >选择物品</el-button>
			 </el-form-item>
			 <el-form-item label="库存数量">
		 		<el-input v-model="vkcsl" :readonly="true" disabled  icon="add" class="input"></el-input>
		  </el-form-item>
          <el-form-item label="退货单价">
		 		<el-input v-model="vwpdj" type='number'  placeholder="请输入物品单价" icon="add" class="input"></el-input>
		  </el-form-item>
		  <el-form-item label="退货数量">
		 		<el-input v-model="vsl" type='number' placeholder="请输入退货数量" icon="add" class="input"></el-input>
		  </el-form-item>
		  <el-form-item label="退货金额">
		 		<el-input v-model="thje" disabled  placeholder="" icon="add" class="input"></el-input>
		  </el-form-item> 
		 	 <el-form-item label="退货原因">
		 		<el-input type="textarea"  :rows="3"  v-model="vthyy" placeholder="请输入退货原因" icon="add" class="input"></el-input>
		  </el-form-item>
		 </el-form>
		 <div class="en1">
		<el-button type="primary" class="submit" @click="submit">保存</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
		</div>

		<!-- <Xzwplist  @wpchoose="wpchooseed" @close="wpchoosecancel" v-if="showchoselist"  ></Xzwplist> -->
		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data" :params="this.wpfl"></Xzwplist>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	// import Wpchooselist from '../wpfx/wpchooselist'
	import Xzwplist from '../bs/xzwp'
	export default {
		props: ['params'],
		components: { Xzwplist},
		data() {
			return {
				wpfl:'',
				showchoselist:false,
				vwpid: '',
				vwpdj:'',
				vwpidmc:'',
				vsl: '',
				vthyy: '',
				vkcsl:'',
				vjsr: '',
//				vje:'',
//				vckid:'',
				         comboxlist:[],
				dialogTableVisible: true,
				portComponents: {
						xzwp : {
								type: 'xzwp',
								toggle: false,
								params: '',
								data: {}
						}
				},
			}
		},
		 created(){
//		 	alert(this.params)
		 	this.wpfl=this.params;
	     },
		methods: {
			submit() {
				//检测
				 this.$store.state.loading = true;
			       if(!this.vwpidmc) {
				 	this.$message.warning('请选择物品名称');
				 	this.$store.state.loading = false;
				 	return;
				   }
			       else if(!this.vsl){
                    this.$message.warning('请输入退货数量');
					this.$store.state.loading = false;
                    return;
                   }else if(!this.vthyy){
                    this.$message.warning('请输入退货原因');
					this.$store.state.loading = false;
                    return;
                   }
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					wpid: this.vwpid,
					sl: this.vsl,
					thyy: this.vthyy,
					thje:this.thje,
					kcsl:this.vkcsl,
					wpdj:this.vwpdj,
					yhid: logininfo.id,
					xxid:logininfo.xxid
				});
				//执行
				this.axios.post(this.$store.state.api + 'wpcgth/insert', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
						this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.danger("服务器繁忙，请重试");
						//this.$emit('close', { type: 'add', cancel: false });
						this.$store.state.loading = false;
					})
			},
			// showwp(){
			// 	this.showchoselist =true;
			// },
			// wpchooseed(josndata){
			// 	console.log(josndata)
			// 	console.log(11123232)
			// 	this.vwpidmc = josndata.wpmc;
			// 	this.vwpid=josndata.wpid;
			// 			this.showchoselist=false;
			// },
			// wpchoosecancel(){
			// 			this.showchoselist=false;
			// },
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			},
				componentsShow (type,data) { //显示组件
						console.log(type,data)
						for ( let i in this.portComponents ) {
								if (type == this.portComponents[i].type) {
										console.log(this.portComponents[i])

										this.portComponents[i].toggle = true;
										this.portComponents[i].params = data;

										if (this.portComponents[i].data.type == 'single') {
												this.portComponents[i].data.index = data.row.id

										}else if(this.portComponents[i].data.type == 'multiple'){
												this.portComponents[i].data.index = this.multipleDelNum;

										}else{
												return;
										}
										return;
								}
						}

				},
				componentsHide (setting) { //关闭组件
						console.log(setting)
						console.log(1212)
						if(setting.data){
						console.log(setting.data[0].mc)
						this.vwpidmc = setting.data[0].mc
						this.vwpid = setting.data[0].id
//						 this.vwpdj=setting.data[0].jcjg
						 this.vkcsl=setting.data[0].kcsl
						 for ( let i in this.portComponents ) {
								if (setting.type == this.portComponents[i].type) {
										this.portComponents[i].toggle = false;
										if (this.portComponents[i].type == 'singleDelete') {
												this.dataList.splice(setting.index,1)
										}
										return;
								}
						}
						}else{
						for ( let i in this.portComponents ) {
								if (setting.type == this.portComponents[i].type) {
										this.portComponents[i].toggle = false;
										if (this.portComponents[i].type == 'singleDelete') {
												this.dataList.splice(setting.index,1)
										}
										return;
								}
						}
						}
				}
		},
		 computed: {
          thje(){
            let number = this.vwpdj * this.vsl ;
            if (number<=0) {
              return 0.00
            }else if(number<=this.vkcsl*this.vwpdj){
            	return number
            }else{
            	this.$message.warning('输入退货数量 > 当前库存数量，请核对退货数量')
            }
          },
          }
	}
</script>
<style lang="less" scoped>
.wrap {
	.input-block {
		margin-bottom: 20px;
		text-align: center;
	}
	.bt{
	position: absolute;
	width: 100%;
	height: 50px;
	margin: 0 auto;
	top: 0;
	left: 0;
	background: #50BFFF;
	color:white;
	text-align:left;
	line-height: 50px;
	font-size: 17px;
	padding-left: 15px;
}
               .en1{
						text-align: center;
						width: 100%;
					}
.form {
text-align: left;
margin-top: 20px;
}
	.input {
		width:90%;
		display: inline-block;
	}
	.input1 {
		width:75%;
		display: inline-block;
	}
	.input-block{
		vertical-align: middle;
	}
	.input-block span {
		display: inline-block;
		width: 26%;
		text-align: right;
	}
	.el-form-item {
    margin-bottom: 12px;
}
	.submit {
		width: 120px;
	}
	// 	.wpfl{
	// 	background: #fff;
	// 	position: absolute;
	// 	top: 5px;
	// 	right: -60%;
	// }
}
</style>
